import base from './base';
import axios from './http';
const apiUrl = base.test;
const key = base.key;
// 导出接口
export default {
	// 腾讯地图IP 地址定位接口 
	getIpAddress () {
	    return axios.get(`https://apis.map.qq.com/ws/location/v1/ip?key=${key}`);
	},
	// 获取用户所有地址列表
	getAllAddress () {
	    return axios.get(`${apiUrl}/useraddress/userAddress/appauthapi/getUserAddressList`);
	},
	// 获取地址详情
	getAddress (addressId) {
	    return axios.get(`${apiUrl}/client/customer/address/detail?addressId=${addressId}`);
	},
	// 用户【新增】或【修改】或【设置默认】收货地址【需登录，传递token】
	addAddress (data) { // Form-data 数据格式
	    return axios({
			url: `${apiUrl}/useraddress/userAddress/appauthapi/doAddOrUpdateAddress`,
			method: 'post',
			//设置请求头
			headers: {
				'Content-Type': 'application/x-www-form-urlencoded'
			},
			data,
			transformRequest: [function (data) {
			  let ret = ''
			  for (let it in data) {
				ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
			  }
			  return ret
			}],
		 })
		// return axios.post(`${apiUrl}/useraddress/userAddress/appauthapi/doAddOrUpdateAddress`, data);
		 
	},
	// 删除地址
	delAddress (id) {
	    return axios.delete(`${apiUrl}/useraddress/userAddress/delete?id=${id}`);
	},
	// 高德地图省市县街道分级获取
	getAddressClass(parentAdcode, level) { 
		return axios.get(`${apiUrl}/administrativedivision/baseAdministrativeDivision/apppublicapi/getDivisionsByParent/${parentAdcode}/${level}`);	 
	},
	// 用户默认地址获取，如果没有默认则获取最后维护到【需登录，传递token】
	getDefaultAddress() { 
		return axios.get(`${apiUrl}/useraddress/userAddress/appauthapi/getDefaultAddress`);	 
	}
}
